package top.ochiamalu.aioj.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.ochiamalu.aioj.common.BaseResponse;
import top.ochiamalu.aioj.common.ErrorCode;
import top.ochiamalu.aioj.domain.dto.code.SendUpdatePhoneCodeDTO;
import top.ochiamalu.aioj.exception.BusinessException;
import top.ochiamalu.aioj.service.ValidateCodeService;
import top.ochiamalu.aioj.util.ResultUtils;

import javax.annotation.Resource;

/**
 * 验证代码控制器
 *
 * @author ochiamalu
 * @date 2025/04/09
 */
@RestController
@RequestMapping("/validation")
public class ValidateCodeController {

    @Resource
    private ValidateCodeService validateCodeService;

    @PostMapping("/modify/phone")
    public BaseResponse<Boolean> generateModifyPhoneCode(@RequestBody SendUpdatePhoneCodeDTO sendUpdatePhoneCodeDTO) {
        if (sendUpdatePhoneCodeDTO.getPhone() == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        boolean result = validateCodeService.generateModifyPhoneCode(sendUpdatePhoneCodeDTO.getType(), sendUpdatePhoneCodeDTO.getPhone());
        return ResultUtils.success(result);
    }
}
